#include <stdio.h>

#include "base64.h"

void print_ustr_hex(const unsigned char *str, int len) {
    printf("\n");
    for (int i = 0;i < len; i++) {
        if ( len && (len % 8 == 0)) {
            printf("\n");
        }
        printf("%02x ", str[ i ]);
    }
    printf("\n");
}

int main()
{
    const char *plaintext = "我们都有一个家，名字叫中国。";
    
    int origLen = strlen( plaintext );
    printf("plain text in hex: \n");
    print_ustr_hex( plaintext, origLen);


    printf("plain text: %s\n", plaintext);
    
    char *cipher = base64_encode(plaintext, origLen, NULL );
    printf("cipher text: %s\n", cipher);
    printf("len of cipher: %d\n", strlen( cipher ) );

    int plen;
    unsigned char *plain = base64_decode( cipher, &plen, NULL);


    printf("decode text: %s\n", plain);
    printf("decode text in hex: \n");
    print_ustr_hex( plain, plen);



    free( plain );
    free( cipher );
    return 0;
}